package com.prs.crm.action.sys;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;

import com.prs.crm.domain.sys.CheckingSet;
import com.prs.crm.service.sys.CheckingSetService;

public class CheckingSetAction extends BaseAction{

	private static final long serialVersionUID = 1L;
	private CheckingSet checkingSet;
	private CheckingSetService checkingSetService;
	private String serCode;
	public String getSerCode() {
		return serCode;
	}
	public void setSerCode(String serCode) {
		this.serCode = serCode;
	}
	public CheckingSet getCheckingSet() {
		return checkingSet;
	}
	public void setCheckingSet(CheckingSet checkingSet) {
		this.checkingSet = checkingSet;
	}
	public CheckingSetService getCheckingSetService() {
		return checkingSetService;
	}
	public void setCheckingSetService(CheckingSetService checkingSetService) {
		this.checkingSetService = checkingSetService;
	}
	@Action("editCheckingSet")
	public String editCheckingSet(){	
		this.checkingSet=this.getCheckingSetService().getCheckingSet(serCode);
		return SUCCESS;
	}
	@Action("editOnceChecking")
	public String editOnceChecking(){
		this.checkingSet=this.getCheckingSetService().getCheckingSet(serCode);
		return SUCCESS;
	}
	@Action("editTwiceChecking")
	public String editTwiceChecking(){
		this.checkingSet=this.getCheckingSetService().getCheckingSet(serCode);
		return SUCCESS;
	}
	@Action(value="saveModel",results={
			@Result(name="success",type="redirect",location="editCheckingSet?serCode=${checkingSet.getType()}"),
			@Result(name="error",type="chain",location="editCheckingSet?serCode=${checkingSet.getType()}")
	})
	public String saveModel(){
		CheckingSet checking=this.getCheckingSetService().getCheckingSet("cs01");
		if(checking==null){
			checking=new CheckingSet();
			checking.setType("cs01");
			checking.setTimeModel(checkingSet.getTimeModel());
			this.getCheckingSetService().save(checking);
		}
		else{
			this.checkingSetService.submit(checking);
		}
		checkingSet=checking;
		return SUCCESS;
	}
	@Action(value="saveTimes",results={
			@Result(name="success",type="redirect",location="editCheckingSet?serCode=${checkingSet.getType()}"),
			@Result(name="error",type="chain",location="editCheckingSet?serCode=${checkingSet.getType()}")
	})
	public String saveTimes(){
		CheckingSet checking=this.getCheckingSetService().getCheckingSet("cs01");
		if(checking==null){
			checking=new CheckingSet();
			checking.setType("cs01");
			checking.setTimeModel(checkingSet.getTimeModel());
			this.getCheckingSetService().save(checking);
		}
		else{
			this.checkingSetService.submit(checking);
		}
		checkingSet=checking;
		return SUCCESS;
	}
	@Action(value="saveDefault",results={
			@Result(name="success",type="redirect",location="editOnceChecking?serCode=${checkingSet.getType()}"),
			@Result(name="error",type="chain",location="editCheckingSet?serCode=${checkingSet.getType()}")
	})
	public String saveDefault(){
		CheckingSet checking=this.getCheckingSetService().getCheckingSet("cs01");
		if(checking==null){
			checking=new CheckingSet();
			checking.setType("cs01");
			checking.setTimeModel(checkingSet.getTimeModel());
			this.getCheckingSetService().save(checking);
		}
		else{
			this.checkingSetService.submit(checking);
		}
		checkingSet=checking;
		return SUCCESS;
	}
	
	@Action(value="saveDefaults",results={
			@Result(name="success",type="redirect",location="editTwiceChecking?serCode=${checkingSet.getType()}"),
			@Result(name="error",type="chain",location="editCheckingSet?serCode=${checkingSet.getType()}")
	})
	public String saveDefaults(){
		CheckingSet checking=this.getCheckingSetService().getCheckingSet("cs01");
		if(checking==null){
			checking=new CheckingSet();
			checking.setType("cs01");
			checking.setTimeModel(checkingSet.getTimeModel());
			this.getCheckingSetService().save(checking);
		}
		else{
			this.checkingSetService.submit(checking);
		}
		checkingSet=checking;
		return SUCCESS;
	}
//	@Action(value="saveTime",results={
//			@Result(name="success",type="redirect",location="editCheckingSet?checkingSet=${checkingSet.getId()}"),
//			@Result(name="error",type="chain",location="editCheckingSet?checkingSet=${checkingSet.getId()}")
//	})
//	public String saveTime(){
//		this.getCheckingSetService().submit(checkingSet);
//		return SUCCESS;
//	}	
//	@Action(value="saveOther",results={
//			@Result(name="success",type="redirect",location="editCheckingSet?checkingSet=${checkingSet.getId()}"),
//			@Result(name="error",type="chain",location="editCheckingSet?checkingSet=${checkingSet.getId()}")
//	})
//	public String saveOther(){
//		this.getCheckingSetService().submit(checkingSet);
//		return SUCCESS;
//	}
}
